package cubelabs.nexus.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import cubelabs.nexus.entity.CounsellingSession;

@Repository("counsellingSessionDAO")
public class CounsellingSessionDAO extends BaseDAO<CounsellingSession, Long>{

	@SuppressWarnings("unchecked")
	public CounsellingSession findBySession(Long counselEventId) {
		CounsellingSession counsellingSession = null;
		Criteria crit = getSession().createCriteria(getPersistentClass());
		crit.add(Restrictions.and(Restrictions.eq("session.id", counselEventId)));
		List<CounsellingSession> counsellingSessionList = (List<CounsellingSession>)crit.list();
		if(counsellingSessionList != null && counsellingSessionList.size() > 0){
			counsellingSession = counsellingSessionList.get(0);
		}
		return counsellingSession;
	}
        
}
